<!-- eslint-disable vue/no-export-in-script-setup -->
<route lang="json5">
{
  layout: 'default',
  style: {
    navigationStyle: 'custom',
    navigationBarTitleText: '新品',
  },
}
</route>

<template>
  <view class="container">
    <view class="swiper-container">
      <swiper
        autoplay="true"
        interval="3000"
        circular="true"
        indicator-dots="true"
        indicator-color="rgba(0, 0, 0, .3)"
        indicator-active-color="#000000"
      >
        <swiper-item>
          <wd-img src="/static/images/ic_banner.png" mode="aspectFill" class="swiper-item-image" />
        </swiper-item>
        <swiper-item>
          <wd-img
            src="/static/images/ic_banner01.png"
            mode="aspectFill"
            class="swiper-item-image"
          />
        </swiper-item>
        <swiper-item>
          <wd-img
            src="/static/images/ic_banner02.png"
            mode="aspectFill"
            class="swiper-item-image"
          />
        </swiper-item>
        <swiper-item>
          <wd-img
            src="/static/images/ic_banner03.png"
            mode="aspectFill"
            class="swiper-item-image"
          />
        </swiper-item>
        <swiper-item>
          <wd-img
            src="/static/images/ic_banner04.png"
            mode="aspectFill"
            class="swiper-item-image"
          />
        </swiper-item>
      </swiper>
    </view>

    <wd-tabs v-model="selectedCategory" animated map-num="4" slidable-num="4">
      <wd-tab v-for="(category, index) in categories" :key="index" :title="category.label"></wd-tab>
    </wd-tabs>

    <view class="product-list">
      <view class="item" v-for="item in productItems[selectedCategory]" :key="item.id">
        <!-- 图片 -->
        <image :src="item.largeImg" mode="widthFix"></image>
        <!-- 标签 -->
        <view class="label">{{ item.label }}</view>
        <!-- 标题 -->
        <view class="title">{{ item.title }}</view>
        <!-- 用户信息 -->
        <view class="name-with-avatar">
          <!-- 头像 -->
          <view class="userimg" :style="{ backgroundImage: 'url(' + item.userimg + ')' }"></view>
          <!-- 名称 -->
          <view class="name">来自{{ item.name }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import userImage from '@/static/images/icon.png'
import img1 from '@/static/images/ic_product01.png'
import img2 from '@/static/images/ic_product02.png'
import img3 from '@/static/images/ic_product03.png'
import img4 from '@/static/images/ic_product04.png'

const productItems = reactive([
  [
    {
      id: '1',
      largeImg: img1,
      label: '#带你快速体验新款',
      title: '重磅推荐，MD热水器新品试用中',
      userimg: userImage,
      name: 'ER111',
    },
    {
      id: '2',
      largeImg: img2,
      label: '#带你快速体验新款',
      title: '重磅推荐，MD咖啡新品试用中',
      userimg: userImage,
      name: 'ER111',
    },
    {
      id: '3',
      largeImg: img3,
      label: '#带你快速体验新款',
      title: '重磅推荐，MD热水器新品试用中',
      userimg: userImage,
      name: 'ER111',
    },
    {
      id: '4',
      largeImg: img4,
      label: '#带你快速体验新款',
      title: '重磅推荐，MD咖啡新品试用中',
      userimg: userImage,
      name: 'ER111',
    },
  ],
  [
    {
      id: '1',
      largeImg: img1,
      label: '#带你快速体验新手机',
      title: '重磅推荐，MD手机免费送',
      userimg: userImage,
      name: 'ER111',
    },
    {
      id: '2',
      largeImg: img2,
      label: '#带你快速体验新手机',
      title: '重磅推荐，MD手机免费送',
      userimg: userImage,
      name: 'ER111',
    },
    {
      id: '3',
      largeImg: img3,
      label: '#带你快速体验新手机',
      title: '重磅推荐，MD手机免费送',
      userimg: userImage,
      name: 'ER111',
    },
    {
      id: '4',
      largeImg: img4,
      label: '#带你快速体验新衣服',
      title: '重磅推荐，MDT恤额新品',
      userimg: userImage,
      name: 'ER111',
    },
  ],
])

const categories = reactive([
  { label: '精品' },
  { label: '手机' },
  { label: '衣服' },
  { label: '穿搭' },
  { label: '家居' },
  { label: '电脑' },
  { label: '食品' },
  { label: '生鲜' },
])
const selectedCategory = ref(0)
</script>

<style lang="scss" scoped>
.container {
  .swiper-container {
    width: 100%;
    height: 350rpx;
    .swiper-item-image {
      width: 100%;
      height: 100%;
      border-radius: 5%;
    }
  }
  .product-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0 40rpx;
    margin-top: 30rpx;
    .item {
      position: relative;
      width: 48%;
      margin-bottom: 40rpx;
    }

    .item image {
      width: 100%;
      border-radius: 16rpx;
    }

    .label,
    .title {
      margin-top: 20rpx;
      overflow-wrap: break-word;
      white-space: normal;
    }

    .label {
      width: fit-content;
      padding: 4px 10px;
      font-size: 28rpx;
      color: black;
      border: 4rpx solid #6f6e6e;
      border-radius: 30rpx;
    }

    .title {
      overflow: hidden;
      font-size: 32rpx;
      color: #333;
    }

    .name-with-avatar {
      display: flex;
      align-items: center;
      margin-top: 20rpx;
      .userimg {
        width: 60rpx;
        height: 60rpx;
        margin-right: 20rpx;
        background-size: cover;
        border-radius: 50%;
      }

      .name {
        font-size: 30rpx;
        color: #333;
        overflow-wrap: break-word;
        white-space: normal;
      }
    }
  }
  .wd-tabs {
    margin-top: 30rpx;
  }
}
</style>
